#============================================================
#    Role Input Control
#============================================================
# - datetime: 2023-01-11 13:27:06
#============================================================
## 控制角色的运动
class_name RoleInputControl
extends Node2D


@export
var negative_x: String = "ui_left"
@export
var positive_x: String = "ui_right"
@export
var negative_y: String = "ui_up"
@export
var positive_y: String = "ui_down"


@onready
var role := get_parent() as BaseRole


func _ready():
	set_physics_process(false)
	
	# 等待让父节点准备完成后里面才加载完 @onready 节点
	role.ready.connect(func():
		
		set_physics_process(role.property_management.get_property(Const.Property.HEALTH, 0) > 0)
		
		Aspect.after(role.property_management.property_changed, func(property, previous, current):
			# 生命值超过 0 才能使用
			if property == Const.Property.HEALTH:
				set_physics_process(current > 0)
		)
		
	, Object.CONNECT_ONE_SHOT)


func _physics_process(delta):
	# 节点根据输入的方向进行移动
	role.move_controller.move_direction(
		Input.get_vector(
			negative_x, positive_x, 
			negative_y, positive_y
		)
	)
